package com.mimosa.common.system.login;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mimosa.common.dao.HibernateDao;
import com.mimosa.common.service.CommonService;
import com.mimosa.common.system.department.TDepartment;
import com.mimosa.common.system.department.TDepartmentDao;
import com.mimosa.common.system.user.TUser;
import com.mimosa.common.system.user.TUserDao;
import com.mimosa.util.config.Page;

/**
 * 登录信息的业务类
 * 
 * @filename LoginService.java
 * @author ggeagle
 * @date 2013-7-14 下午10:21:31
 */
@Service
@Transactional
public class LoginService extends CommonService<TLogin, String> {
	@Autowired
	private TLoginDao loginDao;

	@Autowired
	private TUserDao userDao;

	@Autowired
	private TDepartmentDao departmentDao;

	/**
	 * 查找浏览记录
	 * 
	 * @return
	 */
	public Page<TLogin> staticsByUser(Page<TLogin> page) {
		page = loginDao.staticsByUser(page);
		TUser user = null;
		for (TLogin login : page.getResult()) {
			user = this.userDao.get(login.getUserId());
			if (StringUtils.isNotBlank(user.getDepartmentId())) {
				TDepartment department = this.departmentDao.get(user
						.getDepartmentId());
				user.setDepartmentName(department.getDepName());
			}
			login.setUser(user);
		}
		return page;
	}

	@Override
	protected HibernateDao<TLogin, String> getHibernateDao() {
		return this.loginDao;
	}
}